package com.netx.generics.translation;
import com.netx.generics.basic.Checker;

import java.util.Iterator;


public abstract class FirstStep<T> extends TranslationStep {

	private final T initialObject;
	
	protected FirstStep(T initialObject) {
		Checker.checkNull(initialObject, "initialObject");
		this.initialObject = initialObject;
	}
	
	protected T getInitialObject() {
		return initialObject;
	}

	// for Translator:
	Iterator<TranslationStep> iterator() {
		return new StepIterator(this);
	}

	private class StepIterator implements Iterator<TranslationStep> {
		
		private TranslationStep _current;
		
		public StepIterator(FirstStep<T> firstStep) {
			_current = firstStep;
		}
		
		public boolean hasNext() {
			return _current != null;
		}
		
		public TranslationStep next() {
			TranslationStep tmp = _current;
			_current = _current.getNextStep();
			return tmp;
		}
		
		public void remove() {
			throw new UnsupportedOperationException("remove");
		}
	//.
	}
}
